import Common from '../../../common/common.js';
let common = new Common;
const app = getApp();
Page({
  data: {
      list:[],
    pageNumber:1,
      size:10,
    isEnd: false, //是否到底
    psType:'',
    type:'',
    orgSeq:'',
    orderId:'',//订单id
  },
  onPullDownRefresh: function () {
    this.setData({
      
      pageNumber: 1,
      isEnd: false
    })
    this.getList(1, 1)
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1200)

  },
  onReachBottom: function () {
    if (!this.data.isEnd) {
      let pageNumber = this.data.pageNumber;
      pageNumber += 1;
      this.getList(pageNumber, 2);
      wx.showLoading({
        title: '正在加载中...',
      })
      this.setData({
        pageNumber
      })
    }



    // if (!this.data.isEnd) {
    //   let page = this.data.page;
    //   page += 1;
    //   this.getList(page, 2)
    //   wx.showLoading({
    //     title: '正在加载中...',
    //   })
    //   this.setData({
    //     page
    //   })
    // }
  },
  getList:function(page,type){
    console.log(this.data.orgSeq)
    common.requestAjax('/api/user-service/v1/user/queryUsersById', 'POST', {
      page:this.data.page,
      size:this.data.size,
      condition: { orgSeq: this.data.orgSeq}
    }).then(res => {
      if (res.data.code == 1) {
        let list = this.data.records || [];
        let isEnd = this.data.isEnd;
        if (type == 1) {
          //下拉刷新
          list = res.data.records;
          isEnd = false;
        } else if (type == 2) {
          //上拉加载
          list = list.concat(res.data.records);
          if (res.data.records.length == 0) {
            //最后一行没数据 到底了
            isEnd = true;
          }
          setTimeout(() => {
            wx.hideLoading()
          }, 500)
        }
        this.setData({
          list: res.data.records,
          isEnd,
        })
      }
    }).catch(err => {
      console.log(err);
    })
  },
  root:function(e){
    let setPsType = 5;
    let item = e.currentTarget.dataset.item
    wx.setStorageSync('psuser', item)
    wx.navigateBack();
    // wx.redirectTo({
    //   url: '/pages/orderMgt/orderInfo/orderInfo?psId=' + item.userId + '&psType=' + this.data.psType + '&setPsType=' + setPsType + '&ture=' + 1 + '&id=' + this.data.orderId + '&itemname=' + item.realName + '&itemtel=' + item.tel + '&type=' + this.data.type + '&psPicUrl=' + item.headPicUrl
    // })
    // wx.navigateTo({
    //   url: '/pages/orderMgt/orderInfo/orderInfo?psId=' + item.userId + '&psType=' + this.data.psType + '&setPsType=' + setPsType + '&ture=' + 1 + '&id=' + this.data.orderId + '&itemname=' + item.realName + '&itemtel=' + item.tel + '&type=' + this.data.type + '&psPicUrl=' + item.headPicUrl
    // })
  },
  onLoad: function (options) {
    let orgSeq = app.globalData.orgSeq;
    console.log(options)
    this.setData({
      psType:options.psType,
      orgSeq: orgSeq,
      orderId: options.orderId,
      type:options.type
    })
    this.getList(1, 1);
  },
  onShow: function () {

  },
})